﻿<include file="Index/_meta"/>
<body>
<input type="hidden" id="TenantId" name="TenantId" value="" />
<div class="header"></div>
<div class="loginWraper">
  <div style="margin:0 auto 3% auto;text-align:center" class="row cl">
    <img src="__ROOT__/Public/temp/Thumb/b1.jpg" alt="" height="300" width="100%">
  </div>
  <div id="loginform" class="loginBox">
    <form class="form form-horizontal" id="userForm">
      <div class="row cl">
        <label class="form-label col-xs-2"><i class="Hui-iconfont">&#xe60d;</i></label>
        <div class="formControls col-xs-8">
          <input id="username" name="username" type="text" placeholder="账户" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <label class="form-label col-xs-2"><i class="Hui-iconfont">&#xe60e;</i></label>
        <div class="formControls col-xs-8">
          <input id="pwd" name="password" type="password" placeholder="密码" class="input-text size-L">
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-2">
          <input class="input-text size-L" name="verify" type="text" placeholder="验证码" onblur="if(this.value==''){this.value='验证码:'}" onclick="if(this.value=='验证码:'){this.value='';}" value="验证码:" style="width:150px;">
          <img src="{:U('Admin/login/verify_c')}" id="imageVerify"> <a id="kanbuq" href="javascript:;">看不清，换一张</a> </div>
      </div>
     <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-2">
          <label for="online">
            <input type="checkbox" name="online" id="online" value="userOnline">
            7天使我保持登录状态</label>
        </div>
      </div>
      <div class="row cl">
        <div class="formControls col-xs-8 col-xs-offset-2">
          <input name="" type="button" class="btn btn-success radius size-L" value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;" id="userLogin">
        </div>
      </div>
    </form>
  </div>
</div>
<div class="footer">Copyright 上海优婴汇电子商务有限公司</div>
<script type="text/javascript" src="__ROOT__/Public/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="__ROOT__/Public/static/h-ui/js/H-ui.min.js"></script>
<include file="Index/_footer"/>
<script>
  var Scope = {
    "UserLogin":"./admin.php?c=login&a=loginUser",
    "testToken": "./admin.php?c=login&a=acceptToken"
  };
  function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
  }
  function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1);
      if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
    }
    return "";
  }
  $(function(){
/*    if(getCookie("token")){
      var dataToken = {"token":getCookie("token")};
      $.post(Scope.testToken,dataToken,function(res){

      },"json")
    }*/
    $("#kanbuq").click(function(){
      var imageSrc = $("#imageVerify").attr("src");
      if(imageSrc){
        if( imageSrc.indexOf('?')>0){
          $("#imageVerify").attr("src", imageSrc+'&random='+Math.random());
        }else{
          $("#imageVerify").attr("src", imageSrc.replace(/\?.*$/,'')+'?'+Math.random());
        }
      }else{
        return false;
      }
    });
    //提交表单
    $("#userLogin").click(function(){
      var userData = $("#userForm").serializeArray();
      var userPost = {};
      if(getCookie("token")){
        userPost.token = getCookie("token");
      }
      $(userData).each(function(i){
        userPost[this.name] = this.value;
      });
      $.post(Scope.UserLogin,userPost,function(res){
        if(res.status == 0){
          dialog.error(res.info);
        }
        if(res.status == 1){
          if($('#online').is(':checked')) {
            var day = 60*60*24*7;
            setCookie("token",res.token,day);
            console.log("online");
          }
          dialog.success(res.info,res.url);
        }
      },"json")
    });
  })
</script>
</body>
</html>